/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package no.ffi.tpm.aik;

import java.util.Arrays;
import no.ffi.tpm.crypto.SignedObject;

/**
 *
 * @author Federico Mancinie <fma at ffi.no>
 */
public class PCRAttestation extends SignedObject {
    private byte[] nonce;
    private byte[] PCRHash;
    
    public PCRAttestation(byte[] buffer,byte[] signature,byte[] nonce){
        super(buffer,signature);
        this.nonce=nonce;
        byte[] tPCRHash=new byte[buffer.length-26];
        System.arraycopy(buffer, 26, tPCRHash, 0, tPCRHash.length);
        this.PCRHash=tPCRHash;
    }
    
    /**
     * Check that the PCR values are the same as the ones attested at AIK creation
     * optionally with a new nonce to avoid replay attacks on LK certification.
     * @param nonce The nonce used in this PCR quote operation on the TPM client
     * @param AIKattest The PCR quote used at AIK creation and stored in the AIK certificate
     * @return True if the PCR values are identical to those when the AIK was created
     */
     public boolean verify(byte[] nonce,byte[] AIKattest){
                   
        //boolean valid=true;
        byte[] PCRTemplate=AIKattest.clone();
        System.arraycopy(nonce, 0, PCRTemplate, 6, nonce.length);
        return Arrays.equals(this.getNonce(), nonce)&&Arrays.equals(PCRTemplate,object);
    
        
    }

    /**
     * @return the nonce
     */
    public byte[] getNonce() {
        return nonce;
    }

    /**
     * @return the PCRHash
     */
    public byte[] getPCRHash() {
        return PCRHash;
    }
}
